package com.zhiyou.app.shop.website.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiyou.app.shop.common.util.ShopConstants;
import com.zhiyou.app.shop.website.dao.IDicItemDao;
import com.zhiyou.app.shop.website.dao.pojo.DicItem;
import com.zhiyou.app.shop.website.service.IDicItemService;

@Service(value="dicItemService")
public class DicItemServiceImpl implements IDicItemService {
	
	@Autowired
	private IDicItemDao dicItemDao;

	public List<DicItem> findByType(String type) {
		DicItem dicItem = new DicItem();
		dicItem.setType(type);
		dicItem.setFlag(ShopConstants.TRUE);
		return dicItemDao.findByExample(dicItem);
	}

	public DicItem findByTypeAndCode(String type, String code) {
		DicItem dicItem = new DicItem();
		dicItem.setType(type);
		dicItem.setCode(code);
		dicItem.setFlag(ShopConstants.TRUE);
		List<DicItem> list = dicItemDao.findByExample(dicItem);
		if(list != null && list.size() >0){
			return list.get(0);
		}
		return null;
	}

	public DicItem update(DicItem di) {
		dicItemDao.update(di);
		return di;
	}

	public DicItem findbyId(String id) {
		return dicItemDao.findById(id);
	}

}
